package com.rxw.nutmall.oss.controller;

import com.rxw.nutmall.oss.entity.File;
import com.rxw.nutmall.oss.service.FileService;
import com.rxw.nutmall.utils.Result;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/oss/file")
@AllArgsConstructor
@Api(tags = "文件关联关系")
public class FIleController {

    private final FileService fileService;

    @PostMapping("/getObject")
    public Result<File> getObject(@RequestBody File file) {
        return fileService.getObject(file);
    }

    @RequestMapping("/uploadFile")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("folder") String folder) {
        return fileService.uploadFile(file,folder);
    }

    @PostMapping("/getFileUrl")
    public String getFileUrl(@RequestBody File file) {
        return fileService.getFileUrl(file);
    }
}
